#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020/2/27 06:07|06:07
# @Author  : yangdingyi
# @File    : 字母异位词分组
# @Software: PyCharm
from typing import List


class Solution:
    def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
        m = {}
        for ss in strs:
            cs = tuple(sorted(ss))
            if m.get(cs):
                m[cs].append(ss)
            else:
                m[cs] = [ss]
        ans = []
        for k in m:
            ans.append(m[k])
        return ans


solve = Solution()
strs = ["eat", "tea", "tan", "ate", "nat", "bat"]
# strs = ["bob", "boo", "oob"]
print(strs)
print(solve.groupAnagrams(strs))


